import md5 from './md5.js';
import random from './random.js';
import config from '../config.js';

const ticket = function(key) {
	let string = random(12);
	let timestamp = (new Date()).valueOf();
	let sign = key + string + timestamp;
	return string + '.' + md5(sign) + '.' + timestamp;
}

const XRequestId = function(key) {
	if (key === undefined || key === '') {
		key = config.xkey;
	}
	key = key ? key : '2zm38w4zkMy7q4zV2hFuWbJ11FKhVk03';
	return ticket(key)
};

export default XRequestId;
